/*****************************************************************
* @File: main.cpp
* @Description:
* @Author: xine
* @Created: 2019-08-10 11:29:37
* @Copyright: copyright (C) 2019 xinedev.org
* @Modified:
*******************************************************************/

#include <GL/glew.h>
#include <GL/freeglut.h>
#include <iostream>

using namespace std;

const int WIDTH = 1280;
const int HEIGHT = 960;

void OnInit()
{
	glClearColor(1,0,0,0);
}

void OnShutdown()
{
	cout << "quit\n";
}

void OnResize(int nw, int nh)
{
}

void OnRender()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glutSwapBuffers();
}

int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	glutInitContextVersion(4, 3);
	glutInitContextFlags(GLUT_CORE_PROFILE | GLUT_DEBUG);
	glutInitContextProfile(GLUT_FORWARD_COMPATIBLE);
	glutInitWindowSize(WIDTH, HEIGHT);
	glutCreateWindow("Modern OpenGL");

	glewExperimental = GL_TRUE;
	GLenum err = glewInit();
	if(GLEW_OK != err){
		cerr << "Error: " << glewGetErrorString(err) << endl;
	}else{
		if(GLEW_VERSION_4_3){
			cout << "Driver supports OpenGL 4.3\nDetails:\n";
		}
		cout << "\tUsing glew " << glewGetString(GLEW_VERSION) << endl;
		cout << "\tVendor: " << glGetString(GL_VENDOR) << endl;
		cout << "\tRenderer: " << glGetString(GL_RENDERER) << endl;
		cout << "\tVersion: " << glGetString(GL_VERSION) << endl;
		cout << "\tGLSL: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << endl;
	}

	OnInit();
	glutCloseFunc(OnShutdown);
	glutDisplayFunc(OnRender);
	glutReshapeFunc(OnResize);
	glutMainLoop();
	return 0;
}
